(function ($) {
    var SearchForm = function () {
        this.pageCount = 0;
        this.heightList = 0;
        this.userExistCompetition = false;
        this.currentStep = "home";
    };

    SearchForm.prototype.initSearchForm = function () {
    	var self = this; 
        $('.p-news').readmore({speed: 500});
        var url = document.location.href;
        var id = url.split('#')[1];
        self.validReadMore(id);
    }
    
    
    SearchForm.prototype.validReadMore = function(e) {
    	var self = this;
        //var f_td = $('#'+e).parent().parent().get(0).tagName;
        var f_td = $('#'+e).parent().parent();
        var d_read = f_td.next().children('.p-news');
        if(d_read.length){
            d_read.readmore('destroy');
        }else{
            d_read.readmore({speed: 500});
        }
    }
    
    SearchForm.prototype.slideToggle = function(e) {
    	$(e).slideToggle();
    }
    
    SearchForm.prototype.checkBroswer = function() {
        if($.browser.msie && parseInt($.browser.version) <= 6) {
            return true;
        }
            return false;
    }
    
    jQuery(function ($) {
        var searchForm = new SearchForm();
        searchForm.initSearchForm();
        
        $.validator.setDefaults({
        	submitHandler: function() 
            { 
                $(".form-validate").unbind();
                $(".form-validate").submit();
                $("#form-subscribe").unbind();
                $("#form-subscribe").submit();
            }
        });
       
        $(".form-validate").validate();
        $("#form-subscribe").validate();
        
        $('.link-popup').click(function(e) {
           var url = $(this).parent().attr('href'); 
           windowPopup(url);
           return false;
        });
        $(document).on("click",".link-delete", function(e) { 
            e.preventDefult();
    		return confirm('Are you sure want to delete this item?');
    	});
        
        $('.faqs dd').hide();
        $(document).on("click",".page-faq dt", function(e) { 
            $(this).next().slideToggle('normal');
    	});
        
        $(".ivideo").click(function(e) {
            e.preventDefault();
            var url = $(this).attr('data-val');
            $(".ivideo").html('<iframe width="294" height="204" src="'+url+'" frameborder="0" allowfullscreen></iframe>');
        });
        
        $(".video-desc a").click(function(e) {
            e.preventDefault();
            var url = $(this).attr('href');
            $(".ivideo").html('<iframe width="294" height="204" src="'+url+'" frameborder="0" allowfullscreen></iframe>');
        });
        /*
        $(".link-show-share").hover(function(e){
            e.preventDefault();
            if($(".social-share").hasClass("social-hide")){
                $(".social-share").removeClass('social-hide');
            }
        });
        */
        $(".share-email").click(function (e){
            e.preventDefault();
            if($(".form-horizontal").hasClass("frm-email-hide")){
                $(".form-horizontal").removeClass('frm-email-hide');
                var url = document.location.href;
                $(".attached-url").html(url);
            }
        });
        $(".popup-close").click(function(e){
            e.preventDefault();
            if(!$(".form-horizontal").hasClass("frm-email-hide")){
                $(".form-horizontal").addClass('frm-email-hide');
            }
        });
        function windowPopup(url)
        {
            window.open(url, null, "width=700, height=500, scrollbars=yes");
            return false;   
        }
        
      });

})(jQuery);